import React from 'react'
import { HashRouter, Switch, Route } from "react-router-dom";
import AddCategory from './components/admin/AddCategory';
import AddProduct from './components/admin/AddProduct';
import AdminDashboard from './components/admin/AdminDashboard';
import PrivateAdminRoute from './components/admin/PrivateAdminRoute';
import PrivateUserRoute from './components/admin/PrivateCommonUserRoute';
import UserDashboard from './components/admin/UserDashboard';
import Home from './components/core/Home';
import Product from './components/core/Product';
import Shop from './components/core/Shop';
import Signin from './components/core/Signin';
import Signup from './components/core/Signup';

interface routersInterface {
    path:string,
    component: React.ComponentType<any>,
    exact?:boolean,
    RouteComponent?:React.ComponentType<any>
}
const routers: routersInterface[] = [
    {
        path:'/',
        component:Home,
        exact:true
    },
    {
        path:'/shop',
        component:Shop
    },
    {
        path:'/signup',
        component:Signup
    },
    {
        path:'/signin',
        component:Signin
    },
    {
        path:'/user/dashboard',
        component:UserDashboard,
        RouteComponent: PrivateUserRoute
    },
    {
        path:'/admin/dashboard',
        component:AdminDashboard,
        RouteComponent: PrivateAdminRoute
    },
    {
        path:'/create/category',
        component:AddCategory,
        RouteComponent: PrivateAdminRoute
    },
    {
        path:'/create/product',
        component:AddProduct,
        RouteComponent: PrivateAdminRoute
    },
    {
        path:'/product/:productId',
        component: Product
    }
]
const Routers = () => {
    return (
        <HashRouter>
            <Switch>
                {
                    routers.map(( item: routersInterface) =>{
                        if (item.RouteComponent){
                            return <item.RouteComponent key={item.path} path={item.path} component={item.component}  exact={item.exact ? true : false} /> 
                        } else {
                            return <Route key={item.path} path={item.path} component={item.component}  exact={item.exact ? true : false} />
                        }
                    })
                }
            </Switch>
        </HashRouter>
    )
}

export default Routers
